package com.maila.xiaoaodispatch.api;

import android.content.Context;

import com.maila.xiaoaodispatch.net.NetWork;
import com.maila.xiaoaodispatch.net.VolleyInterface;
import com.maila.xiaoaodispatch.utils.Constants;

import java.io.File;
import java.util.HashMap;
import java.util.List;

/**
 * Created by mark on 2017/12/7.
 */

public class DispatchApi extends NetWork {

    public static final String URL_LOGIN = Constants.URL_ROOT_XIAOAO + "/index.php?ctrl=mapips"; //版本服务器地址

    public DispatchApi(Context ctx, VolleyInterface listener) {
        super(ctx, listener);
    }

    public DispatchApi(Context ctx, VolleyInterface listener, String tag) {
        super(ctx, listener, tag);
    }

    /**
     * 用户登录
     *
     * @param username
     * @param pwd
     */
    public void login(String username, String pwd) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("username", username);
        query.put("password", pwd);
        requestPost(URL_LOGIN, "userlogin", query);
    }

    /**
     * 用户登录
     */
    public void logout() {
        requestGet(URL_LOGIN, "logout");
    }

    /**
     * 添加提现密码
     *
     * @param pwd
     */
    public void set_withdraw_pwd(String pwd) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("pay_password", pwd);
        requestPost(URL_LOGIN, "pay_password", query);
    }

    /**
     * 获取消息列表
     *
     * @param page
     * @param size
     */
    public void get_message_list(int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "message_all", query);
    }

    /**
     * 获取用户信息
     */
    public void getuserinfo() {
        requestGet(URL_LOGIN, "user");
    }

    /**
     * 修改用户信息
     *
     * @param logo
     * @param name
     * @param sex
     * @param age
     * @param phone
     * @param adcode
     */
    public void set_user_info(String logo, String name, String sex, String age, String phone, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("logo", logo);
        query.put("name", name);
        query.put("sex", sex);
        query.put("age", age);
        query.put("phone", phone);
        query.put("adcode", adcode);
        requestPost(URL_LOGIN, "information", query);
    }

    /**
     * 注册接口
     *
     * @param realname
     * @param carid
     * @param just_img
     * @param back_img
     * @param num 注册码
     * @param adcode
     */
    public void set_register(String realname, String phone, String pwd, String carid, String just_img, String back_img, String num, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("realname", realname);
        query.put("phone", phone);
        query.put("num", num);
        query.put("password", pwd);
        query.put("card_id", carid);
        query.put("just_img", just_img);
        query.put("back_img", back_img);
        query.put("adcode", adcode);
        requestPost(URL_LOGIN, "register", query);
    }


    /**
     * 获取我的订单
     *
     * @param page
     * @param size
     */
    public void get_my_order_list(int page, int size) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        requestGet(URL_LOGIN, "my_order", query);
    }

    /**
     * 未完成订单
     * @param page
     * @param size
     */
    public void get_unfinished_order_list(int page, int size,String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        query.put("adcode", adcode);
        requestGet(URL_LOGIN, "unfinished_order", query);
    }

    /**
     * 抢单大厅列表
     * @param page
     * @param size
     * @param adcode
     */
    public void get_all_order_list(int page, int size,String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        query.put("adcode", adcode);
        requestGet(URL_LOGIN, "orders", query);
    }
    /**
     * 个人主页
     * 个人主页
     *
     */
    public void getmy_evaluate() {
        requestGet(URL_LOGIN, "my_evaluate", null);
    }

    /**
     * 获取配送地址列表
     *
     * @param page
     * @param size
     */
    public void get_address_list(int page, int size, String adcode) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("page", page);
        query.put("size", size);
        query.put("adcode", adcode);
        requestGet(URL_LOGIN, "address", query);
    }

    /**
     * 接单
     *@param type 1.跑腿—取件
    2.跑腿—快递
    3.外卖
     */
    public void get_order(String id,int type) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", id);
        query.put("type", type);
        requestPost(URL_LOGIN, "grab_order", query);
    }

    /**
     * 取货
     *
     * @param type 1 取件 2 快递 3  外卖
     */
    public void order_pickup(String orderid,int  type) {
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", orderid);
        query.put("type", type);
        requestPost(URL_LOGIN, "wai_pickup", query);
    }

    /**
     * 完成外卖
     * @param orderid
     */
    public void complete_waimai(String  orderid){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", orderid);
        query.put("type", "3");
        requestPost(URL_LOGIN, "wai_finish", query);

    }

    /**
     * 完成跑腿
     * @param orderid
     * @param type
     */
    public void complete_paotui(String  orderid,int type){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", orderid);
        query.put("type", type);
        requestPost(URL_LOGIN, "pao_finish", query);

    }

    /**
     * 设置快递金额
     * @param orderid
     * @param weight
     * @param cost
     */
    public void set_pao_fee(String  orderid,String  weight,String cost){
        HashMap<String, Object> query = new HashMap<String, Object>();
        query.put("orderid", orderid);
        query.put("weight", weight);
        query.put("cost", cost);
        requestPost(URL_LOGIN, "pao_finish", query);

    }

    

      /**
     * 上传单张图片
     * @param filepartname
     * @param file
     */
    public  void  uploadimg(String  filepartname, File file){
        uploadOneImg(URL_LOGIN, "update_address", null,filepartname,file);
    }
    /**
     * 上传多张图片
     * @param filepartname
     * @param file
     */
    public  void  uploadmultimg(String  filepartname, List<File> file){
        uploadMutiImg(URL_LOGIN,"update_address", null,filepartname,file);
    }

}
